<template>
  <div class="goods-list-item">
    <img :src="goodsItem.show.img" alt="" @load="imageLoad" />
    <div class="goods-info">
      <p>{{ goodsItem.title }}</p>
      <span class="price">{{ goodsItem.price }}</span>
      <span class="cfav">{{ goodsItem.cfav }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "GoodsListItem",
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  methods: {
    // 每当有图片加载，就传递一个事件
    imageLoad() {
      this.$bus.$emit("imageLoad");
    },
  },
};
</script>

<style lang="scss">
.goods-list-item {
  position: relative;
  width: 48%;
  margin-bottom: 5px;
  img {
    width: 100%;
    border-radius: 5px;
  }
  .goods-info {
    font-size: 12px;
    text-align: center;
    p {
      margin-top: 5px;
      margin-bottom: 3px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .price {
      color: var(--color-high-text);
      margin-right: 20px;
    }
    .cfav {
      position: relative;
      &::before {
        position: absolute;
        content: "";
        left: -15px;
        top: -1px;
        width: 14px;
        height: 14px;
        background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
      }
    }
  }
}
</style>